"""
创建一个疯狂填词（Mad Libs）程序，它将读入文本文件，并让用户在该文本
文件中出现 ADJECTIVE、NOUN、ADVERB 或 VERB 等单词的地方，加上他们自
己的文本。
"""

wordList = ['ADJECTIVE', 'NOUN', 'ADVERB', 'VERB']

file = open('./files/a.txt', 'r')
fileLines = file.readlines()
file.close()

file = open('./files/a_cpy.txt', 'w')
for i in range(len(fileLines)):
    text = fileLines[i].split(" ")
    for word in text:
        if word in wordList:
            print("Enter an %s:" % word)
            inputWord = input()
            text[text.index(word)] = inputWord
    fileLines[i] = " ".join(text)
print()
print("".join(fileLines))
file.write("".join(fileLines))
file.close()
